﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;

namespace E5_KhuyenMaiVang.Email
{
    public class EmailService
    {
        public static bool SendMail(string senderName, string senderEmail, string pass, string receiverEmail, string subject, string content)
        {
            try
            {
                MailMessage msg = new MailMessage();
                msg.From = new MailAddress(senderEmail, senderName, System.Text.Encoding.UTF8);
                
                msg.To.Add(receiverEmail);
                msg.Subject = subject;
                msg.Body = content;
                msg.Priority = MailPriority.High;
                msg.SubjectEncoding = Encoding.UTF8;
                msg.BodyEncoding = Encoding.UTF8;
                msg.IsBodyHtml = true;
                SmtpClient client = new SmtpClient();
                client.Credentials = new NetworkCredential(senderEmail, pass);
                client.Host = "smtp.gmail.com";
                client.Port = 587;
                client.EnableSsl = true;
                client.Send(msg);
                return true;
            }
            catch
            {
                return false;
            }
        }
  
    }
}
